// import req from './request.js'
import vk from '../../uni_modules/vk-unicloud';
import Vue from 'vue'
// 引入 vk框架前端
Vue.use(vk);
var app = new Vue()

function callFunction(data = {}, dbName = {}) {
	if (dbName.dbName) {
		data.dbName = dbName.dbName
	}
	return new Promise((res, rej) => {
		app.vk.callFunction({
			url: dbName.url,
			title: dbName.title == '' || dbName.title ?dbName.title : '请求中...',
			data: data,
			success: (result) => {
				res(result)
			},
			fail(err) {
				rej(err)
			}
		});
	})



	// uni.showLoading({
	//     title: '加载中...',
	//     mask: true,
	// })
	// return new Promise((res, rej) => {
	// 	uniCloud.callFunction({
	// 		name,
	// 		data,
	// 		success(result) {
	// 			// if(!result.success){
	// 			// 	return rej('请求不成功',result)
	// 			// }
	// 			res(result.result )
	// 			uni.hideLoading()
	// 		},
	// 		fail(err) {
	// 			rej(err)
	// 			uni.hideLoading()
	// 		}
	// 	})
	// })

}


// 获取数据列表
export let getData  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/getList`
	})
}

// 获取数据总数
export let getCount  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/count`
	})
}
// 获取求和
export let getSum  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/sum`
	})
}


// 修改数据
export let setDataById  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/updateById`
	})
}

// 修改数据
export let setData  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/update`
	})
}


// 添加数据
export let addData  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/add`
	})
}


// 删除数据
export let delData  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/delete`
	})
}


// 删除数据
export let delDataById  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/deleteById`
	})
}


// 时间查询
export let queryTime  = (data,isLogin) => {
	let type = 'pub'
	if(isLogin){
		type = 'kh'
	}
	return callFunction(data, {
		url: `client/common/base/${type}/queryTime`
	})
}






// 获取金额
export let getUserSumNum  = (data,isLogin) => {
	return callFunction(data, {
		url: `client/user/kh/h5/user_sum_num`
	})
}


// 获取今日下载数量和金额
export let getTodaySumNum  = (data,isLogin) => {
	return callFunction(data, {
		url: `client/user/kh/h5/user_download_num`
	})
}















// 微信授权登录
export let user_authorize = (data) => {
	return callFunction(data, {
		url:'client/user/pub/login/user_authorize/index'
	})
}

// 邮箱登录
export let user_mail_login = (data) => {
	return callFunction(data, {
		url:'client/user/pub/login/user_mail_login/index'
	})
}




// 获取配置
export let getConfig = (data) => {
	return callFunction(data, {
		dbName: "wx_vip_config",
		url: 'client/common/base/pub/getList'
	})
}


// 获取应用数据
export let getObtainApplicationData = (data) => {
	return callFunction(data, {
		dbName: "wx_application",
		url: 'client/common/base/pub/getList'
	})
}


// 获取轮播图
export let getBanner = (data) => {
	return callFunction(data, {
		dbName: "wx_banner",
		url: 'client/common/base/pub/getList'
	})
}



// 获取广告id
export let getAdvertisingIdList = (data) => {
	return callFunction(data, {
		dbName: "wx_advertising",
		url: 'client/common/base/pub/getList'
	})
}



// 获取用户信息
export let getUser = (data) => {
	return callFunction(data, {
		dbName: "wx_user",
		title:"",
		url: 'client/common/base/pub/getList'
	})
}






// 修改用户信息
export let setUserInfo = (data) => {
	return callFunction(data, {
		dbName: "uni-id-users",
		url: 'client/common/base/pub/update'
	})
}

// ai助手
export let getAi = (data) => {
	return callFunction(data, {
		url:'client/common/base/pub/ai'
	})
}

// 获取ai热门提问列表
export let getAiList = (data) => {
	return callFunction(data, {
		dbName:"wx_ai_issue",
		url:'client/common/base/pub/getList'
	})
}


// 邮箱注册
export let registerMail = (data) => {
	return callFunction(data, {
		dbName: "",
		url: 'user/pub/register'
	})
}

// 更新用户信息
export let upUserData = (data) => {
	return callFunction(data, {
		dbName: "uni-id-users",
		url: 'client/common/base/kh/update'
	})
}

 
// 获取奖励中心列表
export let getAwardList = (data) => {
	return callFunction(data, {
		dbName:"wx_award_list",
		url:'client/common/base/pub/getList'
	})
}


// 获取订单列表
export let getOrderList = (data) => {
	return callFunction(data, {
		dbName:"wx_order",
		url:'client/common/base/pub/getList'
	})
}


// 获取VIP列表
export let getVipList = (data) => {
	return callFunction(data, {
		dbName:"wx_vip_list",
		url:'client/common/base/pub/getList'
	})
}



// 微信公众号h5支付
export let wxH5Pay = (data) => {
	return callFunction(data, {
		url:'client/award-centre/kh/pay/wx_h5_pay'
	})
}


// 支付宝h5支付
export let zfbH5Pay = (data) => {
	return callFunction(data, {
		url:'client/award-centre/kh/pay/zfb_pay'
	})
}

// 微信小程序支付 、微信app支付
export let weChatPay = (data) => {
	return callFunction(data, {
		url:'client/award-centre/kh/pay/wx_app_pay'
	})
}


// 支付宝支付查询是否支付成功
export let zfbH5PayQuery = (data) => {
	return callFunction(data, {
		url:'client/award-centre/kh/pay/zfb_pay_query'
	})
}

// 获取配置
export let getWxConfig = (data) => {
	return callFunction(data, {
		dbName: "wx_config",
		url: 'client/common/base/pub/getList'
	})
}


// 用户修改VIP时间
export let userUpdate = (data) => {
	return callFunction(data, {
		url: 'client/user/kh/user_update/index'
	})
}


// 添加订单记录
export let orderAdd = (data) => {
	return callFunction(data, {
		url:'client/award-centre/kh/order/add'
	})
}


// 用户记录
export let recordAdd = (data) => {
	return callFunction(data, {
		dbName:"wx_order",
		title:"",
		url:'client/user/kh/record_add/index'
	})
}